home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / test / test2.c < prev    next >
C/C++ Source or Header  |  1990-07-23  |  1KB  |  75 lines

  1. /* test 2 */
  2.  
  3. #include <stdio.h>
  4.  
  5. extern errno;
  6. int kk = 0;
  7.  
  8. char buf[2048];
  9. main()
  10. {
  11.   int i;
  12.  
  13.   printf("Test  2 ");
  14.   fflush(stdout);        /* have to flush for child's benefit */
  15.  
  16.   for (i = 0; i < 19; i++) {
  17.     test20();
  18.   }
  19.   printf("ok\n");
  20.   exit(0);
  21. }
  22.  
  23.  
  24. test20()
  25. {
  26. /* Test pipes */
  27.  
  28.   int fd[2];
  29.   int n, i, j, ij, q = 0, nn, m = 0, k;
  30.  
  31.   if (pipe(fd) < 0) {
  32.     printf("pipe error.  errno= %d\n", errno);
  33.     exit(0);
  34.   }
  35.   i = fork();
  36.   if (i < 0) {
  37.     printf("fork failed\n");
  38.     exit(0);
  39.   }
  40.   if (i != 0) {
  41.     /* Parent code */
  42.     close(fd[0]);
  43.     for (i = 0; i < 2048; i++) buf[i] = i & 0377;
  44.     for (q = 0; q < 8; q++) {
  45.         if (write(fd[1], buf, 2048) < 0) {
  46.             printf("write pipe err.  errno=%d\n", errno);
  47.             exit(0);
  48.         }
  49.     }
  50.     close(fd[1]);
  51.     wait(&q);
  52.     if (q != 256 * 58) {
  53.         printf("wrong exit code %d\n", q);
  54.         exit(0);
  55.     }
  56.   } else {
  57.     /* Child code */
  58.     close(fd[1]);
  59.     for (q = 0; q < 32; q++) {
  60.         n = read(fd[0], buf, 512);
  61.         if (n != 512) {
  62.             printf("read yielded %d bytes, not 512\n", n);
  63.             exit(0);
  64.         }
  65.         for (j = 0; j < n; j++)
  66.             if ((buf[j] & 0377) != (kk & 0377)) {
  67.                 printf("wrong data: %d %d %d \n ", j, buf[j] & 0377, kk & 0377);
  68.             } else {
  69.                 kk++;
  70.             }
  71.     }
  72.     exit(58);
  73.   }
  74. }
  75.